import {ChangeDetectorRef, Component} from '@angular/core';
import {NavController, NavParams, ToastController} from 'ionic-angular';
import {JidihttpProvider} from "../../providers/jidihttp/jidihttp";

/**
 * Generated class for the UserxiugaiPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-userxiugai',
  templateUrl: 'userxiugai.html',
})
export class UserxiugaiPage {
  /** 性别 **/
  gender:string="f";
  sex:number;
  username_login:string;
  pws:string;
  shouji_change:string;
  nicheng_change:string;
  username_change:string;
  imgg:string;
  constructor(public toastCtrl: ToastController,public navCtrl: NavController, public navParams: NavParams,public cdchange:ChangeDetectorRef,public jidiProvider:JidihttpProvider) {
    this.imgg=this.navParams.get('imgg');
  }

  xiugaiEvent() {
    if(this.gender=="男"){
      this.sex =1;
    }else{
      this.sex =2;
    }

    var params = {
      "name": this.username_change,
      "webchatName": this.nicheng_change,
      "phone": this.shouji_change,
      "loginName": this.username_login,
      "loginPass": this.pws,
      "sex":this.sex,
      "img":this.imgg
    };
    this.jidiProvider.changeUserInfo(params).subscribe(data => {
      this.showToast(data['message']);
      this.cdchange.detectChanges();
    },error => {
      this.showToast("服务器异常");
    });

    console.log('ionViewDidLoad UserxiugaiPage');
  }



  /** 返回提示 **/
  showToast(position: string) {
    let toast = this.toastCtrl.create({
      message: position,
      duration: 2000,
      position: "bottom"
    });

    toast.present(toast);
  }

}
